﻿using Com.Lancetinc.Evs.Helpers;
using Com.Lancetinc.Evs.ViewModels;
using System.Text;
using System.Windows;

namespace Com.Lancetinc.Evs.Cameras
{
    public class CameraPropViewModel : ViewModelBase
    {
        private string mName;
        public string CameraPropName
        {
            get => mName;
            set => SetProperty(ref mName, value);
        }

        private string mToolTip;
        public string CameraPropToolTip
        {
            get => mToolTip;
            set => SetProperty(ref mToolTip, value);
        }

        private int mMin;
        public int CameraPropMin
        {
            get => mMin;
            set => SetProperty(ref mMin, value);
        }

        private int mMax;
        public int CameraPropMax
        {
            get => mMax;
            set => SetProperty(ref mMax, value);
        }

        private int mStep;
        public int CameraPropStep
        {
            get => mStep;
            set => SetProperty(ref mStep, value);
        }

        private bool mCameraPropAuto;
        public bool CameraPropAuto
        {
            get => mCameraPropAuto;
            set => SetProperty(ref mCameraPropAuto, value);
        }

        private int mValue;
        public int CameraPropValue
        {
            get => mValue;
            set => SetProperty(ref mValue, value);
        }

        private Visibility mAutoCheckboxVisibility = Visibility.Collapsed;
        public Visibility AutoCheckboxVisibility
        {
            get => mAutoCheckboxVisibility;
            set => SetProperty(ref mAutoCheckboxVisibility, value);
        }

        public void SetProp(CameraProp prop)
        {
            StringBuilder sbToolTip = new StringBuilder();
            if ((prop.ModifyFlag == CameraPropModifyFlag.Manual || prop.ModifyFlag == CameraPropModifyFlag.AutoAndManual))
            {
                if (prop.Max > prop.Min)
                {
                    // 范围：{0} ~ {1}
                    sbToolTip.Append(I18nHelper.Default.GetMessageWithArgs("CameraPropViewModel.Range", prop.Min, prop.Max));
                }
                if (sbToolTip.Length > 0)
                {
                    sbToolTip.Append(I18nHelper.Default.GetMessage("CameraPropViewModel.Separator"));
                }
                // 默认值：{0}
                sbToolTip.Append(I18nHelper.Default.GetMessageWithArgs("CameraPropViewModel.Default", prop.DefaultValue));
            }
            this.CameraPropToolTip = prop.Name + (sbToolTip.Length > 0 ? "  " : "") + sbToolTip.ToString();
            // this.CameraPropToolTip = prop.ToString();
            this.CameraPropName = prop.Name;
            this.CameraPropMin = prop.Min;
            this.CameraPropMax = prop.Max;
            this.CameraPropValue = prop.Value;
            this.CameraPropAuto = prop.AutoFlag == CameraPropAutoFlag.Auto;

            if (prop.ModifyFlag == CameraPropModifyFlag.AutoAndManual)
            {
                this.AutoCheckboxVisibility = Visibility.Visible;
            }
        }
    }
}
